package net.lzzy.practices.web.models;

import lombok.Data;
import net.lzzy.practices.entities.User;
import net.lzzy.practices.utils.JwtUtil;

import java.util.UUID;
@Data
public class VmUser{

    private UUID id;
    private   String nickName;
    private  String userName;

    private String email;
    private String phone;

    private  String token;

    private String avatar;

    private  int type;

    //只能我们自己添加数据,不能外部添加
    private  VmUser(){}
    //构造器
    private  VmUser(User user){
        id=user.getId();
        nickName=user.getNickName();
        userName = user.getUserName();
        phone = user.getPhone();
        avatar=user.getAvatar();
        type=user.getType();
    }
    //登录
    //静态构造方法 推断性会更低，且不能继承
    public  static  VmUser apiLogin(User user){
        VmUser vmUser = new VmUser(user);
       vmUser.setToken(JwtUtil.createToken(user.getId()+""));

        return  vmUser;
    }
    //查看用户权限
    public  static  VmUser create(User user,boolean admin){
        VmUser vmUser = new VmUser(user);
        if(!admin){
            vmUser.setUserName("***");
            vmUser.setType(User.TYPE_STUDENT);
        }


        return  vmUser;

    }



}
